package com.party.course.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.enums.BusinessType;
import com.party.common.utils.poi.ExcelUtil;
import com.party.course.domain.StudentInfo;
import com.party.course.service.IStudentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.course.domain.ApprovalInfo;
import com.party.course.service.IApprovalInfoService;
import com.party.common.core.page.TableDataInfo;

/**
 * 审批申请Controller
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/course/ApprovalInfo" )
public class ApprovalInfoController extends BaseController {
    @Autowired
    private IApprovalInfoService approvalInfoService;


    @Autowired
    private IStudentInfoService studentInfoService;

/**
 * 查询审批申请列表
 */
//@RequiresPermissions("course:ApprovalInfo:list")
@GetMapping("/list" )
    public TableDataInfo list(ApprovalInfo approvalInfo) {
        startPage();
        List<ApprovalInfo> list = approvalInfoService.findList(approvalInfo);
        for (ApprovalInfo info : list) {
            if("0".equals(info.getBusinessType())){
                StudentInfo studentInfo = studentInfoService.view(info.getBusinessId());
                info.setStudentInfo(studentInfo);
            }

        }
        return getDataTable(list);
    }

    /**
     * 导出审批申请列表
     */
    //@RequiresPermissions("course:ApprovalInfo:export")
    @Log(title = "审批申请" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ApprovalInfo approvalInfo) {
        List<ApprovalInfo> list = approvalInfoService.findList(approvalInfo);
        ExcelUtil<ApprovalInfo> util = new ExcelUtil<ApprovalInfo>(ApprovalInfo. class);
        util.exportExcel(response, list, "审批申请数据" );
    }

    /**
     * 获取审批申请详细信息
     */
    //@RequiresPermissions("course:ApprovalInfo:query")
    @GetMapping(value = "/view/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(approvalInfoService.view(id));
    }

    /**
     * 新增审批申请
     */
    //@RequiresPermissions("course:ApprovalInfo:add")
    @Log(title = "审批申请" , businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ApprovalInfo approvalInfo) {
        return toAjax(approvalInfoService.add(approvalInfo));
    }

    /**
     * 修改审批申请
     */
    //@RequiresPermissions("course:ApprovalInfo:edit")
    @Log(title = "审批申请" , businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody ApprovalInfo approvalInfo) {
        return toAjax(approvalInfoService.updateEntity(approvalInfo));
    }

    /**
     * 删除审批申请
     */
    //@RequiresPermissions("course:ApprovalInfo:remove")
    @Log(title = "审批申请" , businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(approvalInfoService.deleteIds(Arrays.asList(ids)));
    }
}
